// JavaScript Document
(function(){
	$('.j_fold').click(function(){
		$(this).closest('.j_passage').toggleClass('open');
	});
	
	var startX, endLeft;
	var container = $('#screenshot').find('ul');
	var containerW = container.outerWidth();
	function touchStart(){
		event.preventDefault();
		if(!event.touches.length){
			return;
		}
		var touch = event.touches[0];
		startX = touch.pageX;
	}
	function touchMove(){
		if(!event.touches.length){
			return;
		}
		var touch = event.touches[0],
			difX = touch.pageX - startX;
		endLeft = container.offset().left + difX;
		container.css({left: endLeft + 'px'});
	}
	function touchEnd(){
		var final = Math.max(-containerW, endLeft);
		final = Math.min(final, 0);
		container.css({left: final + 'px'});
	}
	
	var touch = function(){
		var type = event.type;
		switch(type){
			case 'touchstart':
				touchStart();
				break;
			case 'touchmove':
				touchMove();
				break;
			case 'touchend':
				touchEnd();
				break;
			default:
				break;
		}
	}
	
	container[0].addEventListener('touchstart', touch, false);
	container[0].addEventListener('touchmove', touch, false);
	container[0].addEventListener('touchend', touch, false);
})();